/**
 * Created by DE on 2017/12/25.
 */
var wordOrderNum = "";
var reason = "";
var receiveOnePeople = ""; <!--外部使用字段存储运维人员信息，便于在各个controller中使用  未使用-->




var app = angular.module('myapp', []);
<!-- 电话交互-->

app.repairPeople = {
    userName: null,
    userAccount: null,
    userType: null,
    userAddress: null,
    userPassword: null,
    userPhone: null
};<!-- 用anjular的全局变量存储运维人员信息  未使用-->

$.ajax({
    type: "POST",//请求方式
    url: 'http://localhost:8080/getUserInfo',
    data:  JSON.stringify({"userAccount": 1506101090}),//地址，就是json文件的请求路径
    async: true,
    dataType: "json",//数据类型可以为 text xml json  script  jsonp
    contentType: 'application/json;charset=UTF-8',//解决415错误
    success: function (result) {//返回的参数就是 action里面所有的有get和set方法的参数
 //       console.log(result.data);
        receiveOnePeople =result.data;<!--用ajax方式得到运维人员信息  未使用-->
 //       console.log(receiveOnePeople);
    }, error: function () {
        alert("获取运维人员失败，请重试！");
    }
});
app.controller('PhoneInformationCtrl', function ($scope, $http) {

    $http({
        method: 'GET',
        url: 'http://localhost:8080/webServiceInfo'
    }).then(
        function successback(data) {
     //       console.log(data);
            $scope.phoneNum=data.data.data.content;<!-- 将电话在页面上显示-->
        },
        function errorback() {

            jError("获取服务电话失败,请重试！", {
                VerticalPosition: 'center',
                HorizontalPosition: 'center'
            })
        }
    );




});
<!-- 运维人员信息交互-->

app.controller('InformationCtrl', function ($rootScope, $http) {
    $rootScope.repairmaninfo = {
        userName: null,
        userAccount: 1506101090,
        userType: null,
        userAddress: null,
        userPassword: null,
        userPhone: null
    };

    $http({
        method: 'post',
        url: 'http://localhost:8080/getUserInfo',
        data: {"userAccount": 1506101090}
    }).then(
        function successCallback(response) {
            $rootScope.repairmaninfo = response.data.data;
     //       console.log('>>>>>>>>>运维人员为：');
     //       console.log($rootScope.repairmaninfo);
            app.repairPeople = $rootScope.repairmaninfo;

            receiveOnePeople = $rootScope.repairmaninfo;


        }, function errorCallback(response) {

            jError("获取运维人员数据失败，请刷新！", {
                VerticalPosition: 'center',
                HorizontalPosition: 'center'
            })

        });

    //显示运维人员


});


<!--工单详情交互-->
var suaidanDiv = document.getElementById("receiveTwo");

app.controller('ticketCtrl', function ($http,$scope) {
    $http({
        method: 'GET',
        url: 'http://localhost:8080/queryMyAllWorkOrder/'+1506101090,
    }).then(function successCallback(response) {
     console.log(response);

        $scope.tickets = response.data.data;


      console.log($scope.tickets);

    }, function errorCallback() {

        jError("获取工单详情失败，请刷新！", {
            VerticalPosition: 'center',
            HorizontalPosition: 'center'
        })
    });




    $scope.go = function (ticket) {

        if(ticket.isComplete!=1){

            wordOrderNum = ticket.jobnumber;
            reason = ticket.reason;
            if (ticket.reason == null) {
                var str = prompt("请填写甩单原因", "");
                if (str != null && str != "") {
                    ticket.reason = str;
                    reason = ticket.reason;
                }
            } else {


                angular.element(document.getElementById("receive2")).removeClass("hidden");
                angular.element(document.getElementById("receive2")).addClass("show");


            }


            console.log("工单号+甩单原因");
            console.log(wordOrderNum + reason);

        }else{

            alert("工单已完成，不能被甩单");

        }




    }


});

<!--甩单 所有的甩单按钮都会跳到这来-->
app.controller('suaiDanCtrl', function ($scope,$http) {
    $http({
        method: 'GET',
        url: 'http://localhost:8080/isOnline' //得到运维人员列表
    }).then(function successCallback(response) {

        console.log(response);
        $scope.receives = response.data.data;

        console.log('>>>>>>>>>可甩单运维人员列表为');
        console.log( $scope.receives);

    }, function errorCallback(response) {
        console.log("甩单失败");
        jError("获取运维人员列表失败", {
            VerticalPosition: 'center',
            HorizontalPosition: 'center'
        })
    });

    $scope.gosuaidan = function () {

$scope.test = {
    jobnumber: wordOrderNum,
    receiveOne:$scope.receiveTwo.userAccount,
    receiveTwo:1506101090,
    reason: reason
}


        console.log("甩单需要的数据：");
        console.log(wordOrderNum);
        console.log(receiveOnePeople.userAccount);
        console.log($scope.receiveTwo.userAccount);
        console.log(reason);
        $http({
            method: 'POST',
            url: 'http://localhost:8080/throwWorkOrder',
            data: $scope.test
        }).then(
            function successback() {
                alert('甩单成功');
                angular.element(document.getElementById("receive2")).removeClass("show");
                angular.element(document.getElementById("receive2")).addClass("hidden");

                reason="";


            }, function errorback() {
                jError("甩单失败，请重试！", {
                    VerticalPosition: 'center',
                    HorizontalPosition: 'center'
                })
                angular.element(document.getElementById("receive2")).removeClass("show");
                angular.element(document.getElementById("receive2")).addClass("hidden");

            }
        )
    }

    $scope.suaidanCancel = function () {


        angular.element(document.getElementById("receive2")).removeClass("show");
        angular.element(document.getElementById("receive2")).addClass("hidden");

    }


});

<!--待处理工单交互-->
app.controller('needHandleCtrl', function ($scope, $http) {

    var onePeople  = document.getElementById("receiveOne").innerHTML;
    $http({
        method: 'get',
        url: 'http://localhost:8080/isOnGoingWorkOrder/'+1506101090,
    }).then(function successCallback(response) {



        $scope.unHandtickets = response.data.data;

        console.log('>>>>>>>>>>待处理工单列表为');
        console.log($scope.unHandtickets);

    }, function errorCallback(response) {

        jError("获取未处理工单失败，请刷新！", {
            VerticalPosition: 'center',
            HorizontalPosition: 'center'
        })
    });


    $scope.go = function (ticket) {

        wordOrderNum = ticket.jobnumber;
        reason = ticket.reason;
        if (ticket.reason == null) {
            var str = prompt("请填写甩单原因", "");
            if (str != null && str != "") {
                ticket.reason = str;
                reason = ticket.reason;
            }
        } else {


            angular.element(document.getElementById("receive2")).removeClass("hidden");
            angular.element(document.getElementById("receive2")).addClass("show");


        }


        console.log("工单号+甩单原因");
        console.log(wordOrderNum + reason);


    }


});

<!--个人信息交互-->


app.controller('peopleInformationCtrll', function($http, $scope){

    $scope.repairman = {
        userName: null,
        userAccount: null,
        userType: null,
        userAddress: null,
        userPassword: null,
        userPhone: null
    };



    $scope.peoplePhone =  receiveOnePeople.userPhone;
    $scope.peopleAddress = receiveOnePeople.userAddress;


    console.log($scope.peoplePhone);
    console.log($scope.peopleAddress);
    $scope.saveBtn = false;




//修改电话
    $scope.changephone = function () {



        $scope.repairman = {
            userName:receiveOnePeople.userName,
            userAccount: 1506101090,
            userType:receiveOnePeople.userType,
            userAddress: $scope.peopleAddress,
            userPassword: receiveOnePeople.userPassword,
            userPhone:  $scope.peoplePhone
        };

    //    console.log($scope.repairman);



        if ($scope.repairman.userType == 1) {  //如果是老师就将保存按钮选为不可选中

            alert("教职工请到其他地方修改信息");

            $scope.saveBtn = true;

        } else {

            $http({
                method: 'POST',
                url: 'http://localhost:8080/updateUserInfo',
                data: $scope.repairman
            }).then(
                function successback() {
                    alert("修改成功");

                    $scope.saveBtn = true;
                },
                function errorback() {
                    jError("修改失败", {
                        VerticalPosition: 'center',
                        HorizontalPosition: 'center'
                    })


                }
            )

        }


    };


});


<!-- 业绩交互-->






<!--工单详情过滤 -->




<!--时间过滤  用于对uploadtime字段过滤-->

app.filter('dateDiff', function() { //可以注入依赖
    return function(text) {




        return text.split("").reverse().join("");
    }
});



var dateDiff = function (timestamp) {

    //console.log(timestamp);
    // 补全为13位
    var arrTimestamp = (timestamp + '').split('');
    for (var start = 0; start < 13; start++) {
        if (!arrTimestamp[start]) {
            arrTimestamp[start] = '0';
        }
    }
    timestamp = arrTimestamp.join('') * 1;

    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = now - timestamp;

    // 如果本地时间反而小于变量时间
    if (diffValue < 0) {
        return '不久前';
    }

    // 计算差异时间的量级
    var monthC = diffValue / month;
    var weekC = diffValue / (7 * day);
    var dayC = diffValue / day;
    var hourC = diffValue / hour;
    var minC = diffValue / minute;

    // 数值补0方法
    var zero = function (value) {
        if (value < 10) {
            return '0' + value;
        }
        return value;
    };

    // 使用
    if (monthC > 12) {
        // 超过1年，直接显示年月日
        return (function () {
            var date = new Date(timestamp);
            return date.getFullYear() + '年' + zero(date.getMonth() + 1) + '月' + zero(date.getDate()) + '日';
        })();
    } else if (monthC >= 1) {
        return parseInt(monthC) + "月前";
    } else if (weekC >= 1) {
        return parseInt(weekC) + "周前";
    } else if (dayC >= 1) {
        return parseInt(dayC) + "天前";
    } else if (hourC >= 1) {
        return parseInt(hourC) + "小时前";
    } else if (minC >= 1) {
        return parseInt(minC) + "分钟前";
    }
    return '刚刚';
};


app.filter('newtime', function () {
    return function (input) {


        input = dateDiff(input);

        //alert(input);

        return input;
    }

});

<!--工单完成情况过滤 -->
app.filter('wordStatus', function () {
    return function (input) {

        if(input==1){
            input="已完成";
        }else{
            input="未完成";
        }

        return input;
    }

});









